<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>
			修改房产信息
		</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="css/main.css" media="all">
		<script type="text/javascript" src="lib/loading/okLoading.js"></script>
		<script src="js/axios.js"></script>
		<style>
			.imgs {
				display: none;
			}
		</style>
	</head>
	<body>
		<div class="x-body">
			<form class="layui-form layui-form-pane" action="" id="add">
				<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
					<div class="layui-tab-content">
						<div class="layui-tab-item layui-show">
							<input type="hidden" name="id" value="" />

							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>所属小区
								</label>
								<div class="layui-input-block">
									<select name="community_id" id="community_id" lay-filter="community">

									</select>
								</div>
							</div>
							<script>
								let s = localStorage.getItem("fangchan_edit");
								let fangchan = JSON.parse(s);
								let url = "http://localhost:8080/wuye_war_exploded/XiaoQuController/findNameAll";
								let innerHTML = "<option value=\"0\">---请选择所属小区---</option>";
								axios.get(url).then((r) => {
									if (r.data.code == 200) {
										let arr = r.data.data;
										for (let i = 0; i < arr.length; i++) {
											if (fangchan.xiaoquId == arr[i].id) {
												innerHTML = innerHTML + "<option value=\"" + arr[i].id + "\" selected>" + arr[i]
													.xiaoqumingcheng +
													"</option>"
											} else {
												innerHTML = innerHTML + "<option value=\"" + arr[i].id + "\">" + arr[i]
													.xiaoqumingcheng +
													"</option>"
											}

										}
										document.getElementById("community_id").innerHTML = innerHTML;
									}
								})
							</script>
							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>栋数
								</label>
								<div class="layui-input-block">
									<select name="building_id" id="building_id">

										<option value="0">暂无数据</option>

									</select>
								</div>
							</div>



							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>房产名称
								</label>
								<div class="layui-input-block">
									<input id="fangchanmingcheng" type="text" name="home_name" autocomplete="off"
										placeholder="空制在80个汉字，160个字符以内" class="layui-input" value="">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>户主名称
								</label>
								<div class="layui-input-block">
									<input id="huzhumingcheng" type="text" name="householder" autocomplete="off"
										placeholder="" class="layui-input" value="">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>联系方式
								</label>
								<div class="layui-input-block">
									<input id="tel" type="text" name="phone" autocomplete="off" placeholder=""
										class="layui-input" lay-verify="required|phone" value="">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>房间数
								</label>
								<div class="layui-input-block">
									<input id="fangjianshu" type="text" name="home_number" autocomplete="off"
										placeholder="" class="layui-input" lay-verify="required|number" value="">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>单元
								</label>
								<div class="layui-input-block">
									<input id="danyuan" type="text" name="unit_building" autocomplete="off"
										placeholder="请输入数字" class="layui-input" lay-verify="required|number" value="">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>楼层
								</label>
								<div class="layui-input-block">
									<input id="louceng" type="text" name="floor" autocomplete="off" placeholder="请输入数字"
										class="layui-input" lay-verify="required|number" value="">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>入住时间
								</label>

								<div class="layui-input-inline">
									<input id="enterTime" type="date" class="layui-input" name="rz_time"
										placeholder="入住时间" value="">
								</div>

							</div>
							<div class="layui-form-item layui-form-text">
								<label class="layui-form-label">
									<span class='x-red'>*</span>描述
								</label>
								<div class="layui-input-block">
									<textarea id="description" placeholder="请输入内容" name="desc"
										class="layui-textarea"></textarea>
								</div>
							</div>

							<div class="layui-form-item">
								<button class="layui-btn" type="button" lay-filter="add" lay-submit="">
									保存
								</button>
							</div>
							<!--</form>-->
							<div style="height:100px;"></div>
						</div>

					</div>

				</div>
			</form>
		</div>
		<script src="lib/layui/layui.js" charset="utf-8"></script>
		<script src="js/x-layui.js" charset="utf-8"></script>
		<script src="js/jquery.min.js" charset="utf-8"></script>
		<!--<script src="/static/xiyuan/js/jquery.js" charset="utf-8"></script>-->
		<script>
			layui.use(['laydate', 'element', 'layer', 'form'], function() {
				$ = layui.jquery; //jquery

				laydate = layui.laydate; //日期插件
				lement = layui.element(); //面包导航
				layer = layui.layer; //弹出层

				form = layui.form();
				okLoading.close($);
				form.render();
				var start = {
					min: laydate.now(),
					max: '2099-06-16 23:59:59',
					istoday: false,
					choose: function(datas) {
						//end.min = datas; //开始日选好后，重置结束日的最小日期
						//end.start = datas //将结束日的初始值设定为开始日
					}
				};
				document.getElementById("enterTime").onclick = function() {
					start.elem = this;
					laydate(start);
				};
				document.getElementById("fangchanmingcheng").value = fangchan.fangchanmingcheng;
				document.getElementById("huzhumingcheng").value = fangchan.huzhumingcheng
				document.getElementById("tel").value = fangchan.tel;
				document.getElementById("fangjianshu").value = fangchan.fangjianshu;
				document.getElementById("danyuan").value = fangchan.danyuan;
				document.getElementById("louceng").value = fangchan.louceng;
				document.getElementById("description").value = fangchan.description;
				// let datetime = new Date(fangchan.enterTime);
				// let date = dateTime.toLocaleDateString('zh-CN');
				document.getElementById("enterTime").value = fangchan.enterTime;
				document.getElementById("building_id").value = fangchan.dongshu;

				//监听提交
				form.on('submit(add)', function(data) {
					var home_name = $("input[name='home_name']").val();
					var householder = $("input[name='householder']").val();
					if (home_name == "") {
						layer.msg('房产名称不能为空', {
							icon: 5,
							time: 2000
						});
						return false;
					}
					if (householder == "") {
						layer.msg('户主名称不能为空', {
							icon: 5,
							time: 2000
						});
						return false;
					}
					let xiaoquId = document.getElementById("community_id").value;
					let dongshu = document.getElementById("building_id").value;
					let fangchanmingcheng = document.getElementById("fangchanmingcheng").value;
					let huzhumingcheng = document.getElementById("huzhumingcheng").value;
					let tel = document.getElementById("tel").value;
					let fangjianshu = document.getElementById("fangjianshu").value;
					let danyuan = document.getElementById("danyuan").value;
					let louceng = document.getElementById("louceng").value;
					let description = document.getElementById("description").value;
					let enterTime = document.getElementById("enterTime").value;
					let url = "http://localhost:8080/wuye_war_exploded/FangChanController/edit";
					axios.post(url, {
						id: fangchan.id,
						xiaoquId: xiaoquId,
						dongshu: dongshu,
						fangchanmingcheng: fangchanmingcheng,
						huzhumingcheng: huzhumingcheng,
						tel: tel,
						fangjianshu: fangjianshu,
						danyuan: danyuan,
						louceng: louceng,
						description: description,
						enterTime: enterTime
					}).then((r) => {
						if (r.data.code == 200) {
							layer.msg("修改成功！", {
								icon: 6,
								time: 2000

							})
						} else {
							layer.msg("修改失败！", {
								icon: 5,
								time: 2000
							});
						}
					})

				});

				let communidyName = function(data) {
					let xiaoquId = document.getElementById("community_id").value;
					// document.getElementById("community_id").onchange = function() {
					// 	xiaoquId = document.getElementById("community_id").value;
					// }

					communidy(xiaoquId);
				}
				form.on('select(community)', communidyName);

				//communidy();
				function communidy(xiaoquId) {
					let url = "http://localhost:8080/wuye_war_exploded/DongShuController/findDongShuAll";
					innerHTML = "<option value=\"0\">---请选择所属栋数---</option>";
					axios.post(url, {
						xiaoquId: xiaoquId
					}).then((r) => {
						if (r.data.code == 200) {
							let arr = r.data.data;
							for (let i = 0; i < arr.length; i++) {
								if (fangchan.xiaoquId == arr[i].xiaoquId) {

									innerHTML = innerHTML + "<option value=\"" + arr[i]
										.dongshumingcheng +
										"\" selected>" +
										arr[i].dongshumingcheng +
										"</option>"
								} else {
									innerHTML = innerHTML + "<option value=\"" + arr[i]
										.dongshumingcheng +
										"\" >" +
										arr[i].dongshumingcheng +
										"</option>"
								}


							}
							document.getElementById("building_id").innerHTML = innerHTML;
						}
						layui.form().render('select', {
							elem: '#building_id'
						})
					})
				}
				communidyName(null);
			})
		</script>
		<!--栏目缩略图上传-->
		<script>
			/*$("#community_id").blur(function(){
        communidy()
    });*/


			//window.onload = communidy;
		</script>

	</body>
</html>